/* 
 * @auther GWJ 
 * js部分 
 */
$(function() {
	// 全局变量
	//debugger;
	var subContextPath = "/mesmocustdriverlog";
	// 获取当前协议
	var protocol = window.location.protocol;
	// 获取主机名(IP 或 域名)
	var hostname = window.location.hostname;
	// 获取端口号
	var port = window.location.port;
	// 如果没有显式地指定端口，那么有可能是 80 (http) 或 443(https)
	if (port === '') {
		if (protocol === 'http:') {
			port = '80';
		}
		if (protocol === 'https:') {
			port = '443';
		}
	}
	// 设置项目根路径
	var rootPath = '/ims-mes';
	// 构造
	var contextPath = protocol + '//' + hostname + (port !== '' ? ':' + port : '') + rootPath;
	console.log(contextPath)
	var preQuery = contextPath +subContextPath +"/";
	// 查询数据URL
	var selectDriverLog = preQuery + "query";
	const user = {
		"pageNo": 1,
		"pageSize": 20,
		"orderBy": "string",
		"orderDirection": "string",
		"condition": "list<ConditionDto>",
		"data": "T",
		"extend": "Map"
	}
	// 发送请求到后端
	function fetchData() {
		fetch(selectDriverLog, {
			method: 'POST',
			body: JSON.stringify(user),
			headers: {
				'Content-Type': 'application/json; charset=utf-8'
			}
		})
		.then(response => response.json())
		.then(data => {
			//处理返回的数据
			displayData(data);
			console.log('获取数据成功！');
		})
		.catch(error => console.log('无法获取数据：', error));
	};
	
	// 动态创建元素并插入到页面中
	function displayData(data) {
		const container = document.getElementById('data-container');
		//清空已有数据
		container.innerHTML = '';
		data.rows.forEach(item => {
			const element = document.createElement('div');
			element.className = 'data-item';
			//将数据转换为字符串展示
			element.textContent = JSON.stringify(item);
			container.appendChild(element);
		});
	}
	
	//初始化时调用查询函数
	fetchData();
	
	function addBubble(x, y) {
		const bubble = document.createElement('div');
		bubble.classList.add('bubble');
		bubble.style.left = (x + 15) + 'px';
		bubble.style.top = (y - 60) + 'px';
		document.querySelector('.bubbles').appendChild(bubble);
						
		//动画完成后移除元素
		setTimeout(() => document.querySelector('.bubbles').removeChild(bubble), 200);
	}
	//监听鼠标移动事件并添加气泡
	document.addEventListener('mousemove', e => {
		addBubble(e.clientX, e.clientY);
	});
		
	//获取用于显示自定义光标的元素
	let cursor = document.getElementById('cursor');
		
	//监听鼠标移动事件
	document.addEventListener('mousemove', function(event) {
		//更新自定义鼠标的位置
		cursor.style.top = (event.clientY - 10) + 'px';
		cursor.style.left = (event.clientX + 12) + 'px';
	});
					
	/*const pointer = document.querySelector('.pointer');
					
	const onPointerMove = (e) => {
		const mouseY = e.clientY;
		const mouseX = e.clientX;
		pointer.style.transform = `translare3d(${mouseX - 10}px, ${mouseY - 100}px, 0)`;
	}
	window.addEventListener("mousemove", onPointerMove);*/
	//window.addEventListener("mousedown", onMouseClick);
	/* jquery
	// 初始化jqgrid
	jqgridInit('#bsTable' , options = {
		url : selectDriverLog,
		datatype : "json",
		colNames : colNames,
		colModel : colModel,
		multiselect : true,
		multiselectWidth : 30,
		rowNum : 10,
		autoScroll : true,
		sortname : 'updatedDate',
		sortorder : 'desc',
		height : 'auto',
		gridComplete : function() {
			tableUtils.showPageNumb(gridTable);
		},
		loadComplete : function(data) {
			appUtils.initAppPage(gridTable, colModel, "",$(".dropdown-a"));
		}
	});*/
});